package com.whisperarts.financer.app.model.rcp;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

import com.whisperarts.financer.dao.AccountsDAO;
import com.whisperarts.financer.model.transaction.Category;


public class CategoriesContentProvider implements ITreeContentProvider {
	private CategoriesMockModel model;

	@Override
	public void dispose() {
	}

	@Override
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
//		this.model = (AccountsMockModel) newInput;
	}

	@Override
	public Object[] getElements(Object inputElement) {
		Category rootCategory = AccountsDAO.getCategories().get(0);
		if (rootCategory != null)
			return rootCategory.getSub().toArray();
		else 
			return new Object[0];
//			return AccountsDAO.getCategories().values().toArray();
	}

	@Override
	public Object[] getChildren(Object parentElement) {
		if (parentElement instanceof Category) {
			Category category = (Category) parentElement;
			return category.getSub().toArray();
//		} else if (parentElement instanceof Account) {
//			Account account = (Account) parentElement;
//			return account.getAccountInfo().toArray();
		} else {
			return null;
		}
			
	}

	@Override
	public Object getParent(Object element) {
		return null;
	}

	@Override
	public boolean hasChildren(Object element) {		
		if (element instanceof Category) {
			if (((Category) element).hasSub())
				return true;
		}
//		} else if (!(element instanceof Account)) {
//			return false;
//		}
		return false;
	}
}
